package cn.openea.perpartner.meily.homepagesearch.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.homepagesearch.entity.TaskVo;
import cn.openea.perpartner.meily.homepagesearch.service.ITaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author rains
 * @since 2023-06-29 15:31
 */
@Api(tags = "首页搜索")
@RestController
@RequestMapping("/home/page/search")
public class TaskController extends BaseController {
    @Resource
    private ITaskService taskService;

    @ApiOperation("列表")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody TaskVo vo) {

        if(StrUtil.isBlank(vo.getTab())){
            return AjaxResult.error("获取不到参数tab！");
        }
        startPage();
        List<?> list = this.taskService.selectList(vo);
        TableDataInfo tableDataInfo = getDataTable(list);
        if(BeanUtil.isNotEmpty(tableDataInfo)){
            AjaxResult ajaxResult = AjaxResult.success("查询成功！", tableDataInfo.getRows());
            ajaxResult.put("total", tableDataInfo.getTotal());
            ajaxResult.put("tab", vo.getTab());
            return ajaxResult;
        }
        return AjaxResult.error();

        /*if(StrUtil.isBlank(vo.getTab())){
            return AjaxResult.error("获取不到参数tab！");
        }
        // 工作，不使用默认分页
        if("0".equals(vo.getTab())){
            return this.taskService.selectWorkList(vo);

        } else {
            startPage();
            List<?> list = this.taskService.selectList(vo);
            TableDataInfo tableDataInfo = getDataTable(list);
            if(BeanUtil.isNotEmpty(tableDataInfo)){
                AjaxResult ajaxResult = AjaxResult.success("查询成功！", tableDataInfo.getRows());
                ajaxResult.put("total", tableDataInfo.getTotal());
                ajaxResult.put("tab", vo.getTab());
                return ajaxResult;
            }
        }
        return AjaxResult.error();*/
    }
}
